#include"mainServer.h"
#include"tcpServer.h"
#include<unistd.h>
#include"logger.h"
#include"IpAddressPort.h"
#include<event.h>
#include"reactor.h"
#include"threadPool.h"
MainServer::MainServer()
{
    m_server=new TcpServer(IpAddressPort{"127.0.0.1",8000});
    m_pool=new ThreadPool(3);
    m_reactor=new Reactor();
    m_reactor->AddEventAndHander(m_server->GetSfd(),EV_READ|EV_PERSIST,MainServer::ListenEventCallBac,this);
    m_reactor->Loop();
}
MainServer::~MainServer(){}

void MainServer::ListenEventCallBac(int fd,short events,void*arg)
{
    MainServer* mainServer=static_cast<MainServer*>(arg);
    if(EV_READ|events)
    {
        int cfd=mainServer->m_server->Accept();
        if(-1==cfd)
        {
            LOG_ERROR<<"Accept()failed!";
        }
        write(mainServer->m_pool->GetSubThreadSocketPairFirst(),(char*)&cfd,4);
    }
}

int main()
{
    MainServer ser;
    return 0;
}